package Lee_code;

public class Lee_203 {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    static class Solution {
        public ListNode removeElements(ListNode head, int val) {
            ListNode dummyHead = new ListNode(0);
            dummyHead.next = head;

            //搞一个temp的节点,为的是不影响dummy head的指向
            ListNode temp = dummyHead;
            while (temp.next != null) {
                //如果下一个节点值为val,跳跃连接一下
                if (temp.next.val == val) {
                    temp.next = temp.next.next;
                } else {
                    temp = temp.next;
                }
            }
            return  dummyHead.next;
        }
    }
}
